package com.cg.controller;

import com.cg.context.UserContext;
import com.cg.entity.Result;
import com.cg.service.DemoService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@Slf4j
public class DemoController {

    private final DemoService demoService;


    @GetMapping("/getDemo")
    public Result getDemo() {
        log.info("调用异步方法前 asyncTest -----> userId = {}, userName = {}, userPhone = {}",
                UserContext.getUserId(), UserContext.getUserName(), UserContext.getUserPhone());
        demoService.asyncExecute();
        return Result.success();
    }

    @GetMapping("/asyncTest")
    public Result asyncTest() {
        log.info("调用异步方法前 asyncTest -----> userId = {}, userName = {}, userPhone = {}",
                UserContext.getUserId(), UserContext.getUserName(), UserContext.getUserPhone());
        demoService.asyncExecute();
        return Result.success();
    }

}
